<template>
	<view class="content" :style="app_bg">
		<view class="topTitle" :style="'top:'+zhuangtai+'px'">
			<image class="back" @click="backClick" :src="publicimg.btn_back" mode=""></image>
			<view class="" style="font-size: 32rpx;">
				提现
			</view>
		</view>
		<view class="listindex" :style="user_margin_top">
			<view class="moneytext">
				<view class="font34 fontw500" :style="font_1st">当前余额</view>
				<view @click="goToWithdrawalList" class="font28" :style="font_3rd">提现记录</view>
			</view>
			<view class="moneynumber fontw font72" :style="font_tips+app_border_bottom">
				<text class="font36">￥</text>{{money}}
			</view>
			<text class="withdrawalfunction font34 fontw500" :style="font_1st">提现方式</text>
			<view class="widthdrawalmethodindex">
				<view class="itm1" :style="'border-color:'+publicTextColor.font_3rd_color">
					<image class="lefttop" src="../../static/activewithdraral.png" mode=""></image>
					<image class="wxicon" src="../../static/wxicon.png" mode=""></image>
					<text class="font28" :style="font_3rd">微信</text>
				</view>
				<view class="nextindex">
					<view class="font28" :style="font_3rd">已绑定</view>
					<image class="next" src="../../static/nexticon.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="moneylist" :style="app_theme">
			<view class="moneytext">
				<view class="font34 fontw500" :style="font_1st">提现金额</view>
				<view class="font28" @click="$refs.widthdraralrule.open()" :style="font_3rd">提现说明</view>
			</view>
			<view class="itemindex">
				<block v-for="(item, index) in withdrawarlList" :key="index">
					<view class="itm1" @click="changewithdrawal(item.id,item)" :style="app_border+(withdrawarlId == item.id?'border-color:'+publicTextColor.font_3rd_color+';':'border-color:rgba(0,0,0,0);')">
						<image v-if="withdrawarlId == item.id" class="lefttop" src="../../static/activewithdraral.png" mode=""></image>
						<text class="font44 fontw" style="margin-bottom: 23rpx;" :style="font_1st">{{item.money}}元</text>
						<text class="font24" v-if="item.is_cash_amount_limit == 1" :style="font_3rd">提现次数{{item.member_cash_amount}}/{{item.cash_amount}}次</text>
						<text class="font24" v-if="item.is_cash_amount_limit != 1" :style="font_3rd">无限次数</text>
						<text class="font24" v-if="item.is_advert == 1" :style="font_3rd">需看广告{{item.advert_amount}}次({{item.member_cash_advert}}/{{item.advert_amount}})</text>
						<text class="font24" v-if="item.is_sign == 1" :style="font_3rd">需连续签到{{item.sign_day}}天({{item.member_sign_days}}/{{item.sign_day}})</text>
						<text class="font24" v-if="item.is_invite == 1" :style="font_3rd">需邀请{{item.invite_amount}}人({{item.invite_member_total}}/{{item.invite_amount}})</text>
						<text class="font24" v-if="item.is_keyword == 1" :style="font_3rd">需要口令</text>
					</view>
				</block>
			</view>
		</view>
		<view class="postbtn" @click="postBefore">
			<image class="bgimgpublic" :src="publicimg.btn_lg_primary" mode=""></image>
			<text class="font36 index-1" :style="font_1st">立即提现</text>
		</view>
		<uni-popup ref="widthdraralrule" type="center" :maskClick="false">
			<view class="loadexchagepopup" :style="app_theme">
				<view class="exchagetop" :style="app_border_bg">
					<image @click="$refs.widthdraralrule.close()" class="closepopup" :src="publicimg.btn_close" mode=""></image>
					<text class="font36 index-1" style="margin-top: 28rpx;" :style="font_1st">提现规则</text>
				</view>
				<scroll-view scroll-y="true" class="textrule">
					<rich-text :nodes="desc" class="font30 " :style="font_1st"></rich-text>
				</scroll-view>
			</view>
		</uni-popup>
		<uni-popup ref="postqrcode" type="center">
			<view class="loadexchagepopup" :style="app_theme">
				<view class="exchagetop" :style="app_border_bg">
					<image @click="$refs.postqrcode.close()" class="closepopup" :src="publicimg.btn_close" mode=""></image>
					<text class="font36 index-1" style="margin-top: 28rpx;" :style="font_1st">请上传您的收款二维码</text>
				</view>
				<image class="uploadqr" :style="font_3rd" @click="uploadqucodefunction" :src="uploadimage" mode=""></image>
				<view class="btnlist">
					<view class="btn" @click="beforePostWithdrawar">
						<image class="bgimgpublic" style="z-index: 0;" :src="publicimg.btn_sm_warm" mode=""></image>
						<text class="font30 index-1" :style="font_1st">确定</text>
					</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="keywordspopup" type="center">
			<view class="loadexchagepopup" :style="app_theme">
				<view class="exchagetop" :style="app_border_bg">
					<image @click="$refs.keywordspopup.close()" class="closepopup" :src="publicimg.btn_close" mode=""></image>
					<text class="font36 index-1" style="margin-top: 28rpx;" :style="font_1st">请输入口令</text>
				</view>
				<input class="inputclass" :style="font_1st" type="text" @input="inputKeywords" value="" placeholder="请输入口令" />
				<view class="btnlist">
					<view class="btn" @click="postWithdrawar">
						<image class="bgimgpublic" style="z-index: 0;" :src="publicimg.btn_sm_warm" mode=""></image>
						<text class="font30 index-1" :style="font_1st">确定</text>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	var cssjs = require('@/js/cssjs.js')
	var imagejs = require('@/js/imagejs.js')
	var util = require('@/js/util.js')
	export default {
		data() {
			return {
				publicTextColor:'',
				publicimg:'',
				zhuangtai:0,
				withdrawarlId:0,
				withdrawarlList:[],
				money:0,
				publicimg:'',
				desc:"",
				aditemId:0,
				withdrawalitem:'',
				uploadimage:"../../static/uoload.png",
				imgurl:"",
				appConfig:'',
				keyword:''
			};
		},
		onShow() {
			this.getWithdraralList()
			let that = this
			let aniosgaodu = 0
			uni.getSystemInfo({
				success: function(res) {
					console.log(res);
					that.zhuangtai = res.statusBarHeight;
					var a = res.model.split(' ');
					if (a[0] == 'iPhone') {
						aniosgaodu = 44;
					} else {
						aniosgaodu = 48;
					}
					that.zhuangtai = parseInt(that.zhuangtai)+4
					console.log(that.zhuangtai)
				}
			});
		},
		onLoad() {
			this.setcolorConfig()
		},
		computed:{
			user_margin_top(){
				return `margin-top:${(this.zhuangtai+52)}px;background:${this.publicTextColor.app_theme_color};`
			},
			page_top(){
				return `margin-top:${(this.zhuangtai+52)}px;`
			},
			app_border_bg(){
				return `background:${this.publicTextColor.app_border_color};`
			},
			app_border_top(){
				return `border-top:2rpx solid ${this.publicTextColor.app_border_color};`
			},
			app_border_bottom(){
				return `border-bottom:2rpx solid ${this.publicTextColor.app_border_color};`
			},
			app_border(){
				return `border:2rpx solid ${this.publicTextColor.app_border_color};`
			},
			app_theme(){
				return `background:${this.publicTextColor.app_theme_color};`
			},
			app_bg(){
				return `background:${this.publicTextColor.app_bg_color};`
			},
			font_tips(){
				return `color:${this.publicTextColor.font_tips_color};`
			},
			font_4th(){
				return `color:${this.publicTextColor.font_4th_color};`
			},
			font_3rd(){
				return `color:${this.publicTextColor.font_3rd_color};`
			},
			font_2nd(){
				return `color:${this.publicTextColor.font_2nd_color};`
			},
			font_1st(){
				return `color:${this.publicTextColor.font_1st_color};`
			}
		},
		methods:{
			uploadqucodefunction(){
				let _self = this
				uni.chooseImage({
				    count: 1, //默认9
				    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				    sourceType: ['album'], //从相册选择
				    success: function (res) {
						console.log("123",res.tempFilePaths)
						_self.uploadimage = res.tempFilePaths[0]
						uni.showLoading({
							mask:true
						})
						uni.uploadFile({
							url: util.getUrl("common/upload"), //仅为示例，非真实的接口地址
							filePath: res.tempFilePaths[0],
							name: 'file',
							formData: {
								name: res.tempFilePaths[0]
							},
							header: {
								'content-type': 'multipart/form-data',
								'Authori-zation':uni.getStorageSync("token")
							},
							success: (uploadFileRes) => {
								console.log("1234",JSON.parse(uploadFileRes.data));
								let linshi = JSON.parse(uploadFileRes.data)
								_self.imgurl = linshi.data
								console.log(_self.uploadimage)
								uni.hideLoading()
							},
							fail: (err) => {
								uni.hideLoading()
								uni.showToast({
									icon: 'none',
									title: err,
									duration: 5000
								})
							}
						});
				    }
				});
			},
			inputKeywords(e){
				this.keyword = e.detail.value
			},
			beforePostWithdrawar(){
				if(this.withdrawalitem.is_keyword == 1){
					this.$refs.postqrcode.close()
					this.$refs.keywordspopup.open()
				}else{
					this.postWithdrawar()
				}
			},
			postWithdrawar(){
				let _self = this
				uni.request({
					url: util.getUrl("cash/create"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
						cash_money_id:_self.withdrawarlId,
						account_qrcode:_self.imgurl,
						keyword:_self.keyword
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							uni.showToast({
								title:'申请成功',
								icon:'success'
							})
							_self.withdrawarlId = -1
							_self.$refs.keywordspopup.close()
							_self.$refs.postqrcode.close()
							_self.getWithdraralList()
						}else{
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
						}
					},
				});
			},
			goToWithdrawalList(){
				uni.navigateTo({
					url:'withdrawalList'
				})
			},
			postBefore(){
				if(this.withdrawalitem.is_account_qrcode == 1){
					this.$refs.postqrcode.open()
				}else{
					this.beforePostWithdrawar()
				}
			},
			getWithdraralList(){
				let _self = this
				uni.request({
					url: util.getUrl("cash/index"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							_self.money = res.data.data.money
							_self.withdrawarlList = res.data.data.cash_money_list
							_self.desc = res.data.data.cash_desc
						}
					},
				});
			},
			changewithdrawal(id,item){
				let _self = this
				_self.withdrawalitem = item
				if(item.is_advert == 1 && item.member_cash_advert<item.advert_amount ){
					uni.showModal({
						title:'提示',
						content:"未满足条件",
						confirmText:"看广告",
						success: (res) => {
							if(res.confirm){
								_self.aditemId = item.id
								_self.lookAdVideo(item)
							}
						}
					})
				}else if(item.is_invite == 1 && item.invite_member_total<item.invite_amount){
					uni.showModal({
						title:'提示',
						content:"未满足条件",
						confirmText:"去邀请",
						success: (res) => {
							if(res.confirm){
								uni.navigateTo({
									url:'posterIndex'
								})
							}
						}
					})
				}else if(item.is_sign == 1 && item.member_sign_days<item.sign_day){
					uni.showModal({
						title:'提示',
						content:"未满足条件",
						confirmText:"去签到",
						success: (res) => {
							if(res.confirm){
								uni.switchTab({
									url:'../../pages/task/index'
								})
							}
						}
					})
				}else{
					this.withdrawarlId = id
				}
			},
			lookAdVideo(item){
				let _self = this
				if(_self.openVideo == null){
					_self.openVideo = uni.createRewardedVideoAd({
						adUnitId:item.rewarded_ad_unit,
					})
					_self.openVideo.load((resLoad)=>{
						console.log("adload",resLoad)
					})
					_self.openVideo.onError(function(eError){
						console.log("eError",eError)
					})
					_self.openVideo.onClose((res)=>{
						if(res && res.isEnded){
							_self.postAdVidepNumber()
						}
					})
				}
				uni.showModal({
					title: '提示',
					content: '观看视频以继续' ,
					success: function (res) {
						if (res.confirm) {
							console.log('用户点击确定');
							_self.openVideo.show()
								.catch(() => {
									_self.openVideo.load()
										.then(() => {
											_self.openVideo.show()
										})
										.catch(err => {
											console.log('激励视频 广告显示失败')
											_self.active = false
											uni.showToast({
												title: '暂无激励视频',
												icon: 'none',
												duration: 2000
											});
										})
								})
							// ^视频显示
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			postAdVidepNumber(){
				let _self = this
				uni.request({
					url: util.getUrl("cash/reward_ad"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
						cash_money_id:_self.aditemId
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							uni.showToast({
								title:'操作成功'
							})
							_self.getWithdraralList()
						}
					},
				});
			},
			setcolorConfig(){
				this.publicTextColor = uni.getStorageSync("diyColor")
				this.publicimg = uni.getStorageSync("diyImg")
				this.appConfig = uni.getStorageSync("appconfig")
			},
			backClick(){
				uni.navigateBack({
					
				})
			}
		}
	}
</script>

<style lang="scss">
	.postbtn{
		width: 690rpx;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;
		margin-bottom: 138rpx;
		image{
			z-index: 0;
		}
	}
	.loadexchagepopup{
		display: flex;
		align-items: center;
		flex-direction: column;
		padding-bottom: 40rpx;
		border-radius: 15rpx;
		position: relative;
		width: 690rpx;
		.inputclass{
			border-radius: 14rpx;
			padding: 10rpx 20rpx;
			box-sizing: border-box;
			height: 64rpx;
			width: 600rpx;
			border: 1rpx solid;
		}
		.uploadqr{
			width: 240rpx;
			height: 240rpx;
			margin-bottom: 60rpx;
			margin-top: 60rpx;
			border-radius: 20rpx;
			border: 2rpx solid;
			box-sizing: border-box;
			padding: 10rpx;
		}
		.textrule{
			box-sizing: border-box;
			padding: 3rpx 56rpx 46rpx 51rpx;
			height: 500rpx;
		}
		.text1{
			text-align: center;
			line-height:45rpx;
		}
		.btnlist{
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 45rpx;
			.btn{
				display: flex;
				align-items: center;
				justify-content: center;
				width: 350rpx;
				height: 60rpx;
				position: relative;
			}
		}
		.centerimage{
			width: 265rpx;
			height: 247rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-bottom: 43rpx;
			position: relative;
			.exchangegoodsimage{
				width: 127rpx;
				height: 169rpx;
				background-color: #FFFFFF;
				z-index: 1;
			}
		}
		.exchagetop{
			position: relative;
			width: 690rpx;
			height: 80rpx;
			display: flex;
			justify-content: center;
			border-radius: 15rpx 15rpx 0 0;
			margin-bottom: 43rpx;
			.closepopup{
				position: absolute;
				right: 30rpx;
				top:30rpx;
				height: 31rpx;
				width: 31rpx;
			}
			.imagetop{
				position: absolute;
				top: 0;
				z-index: 0;
				height: 92rpx;
				width: 445rpx;
			}
		}
	}
	.moneylist{
		width: 690rpx;
		box-sizing: border-box;
		padding: 30rpx 0 30rpx 30rpx;
		display: flex;
		flex-direction: column;
		border-radius: 20rpx;
		margin-bottom: 44rpx;
		.itemindex{
			display: flex;
			flex-wrap: wrap;
			width: 100%;
			.itm1{
				position: relative;
				display: flex;
				align-items: center;
				justify-content: center;
				width: 305rpx;
				border-radius: 10rpx;
				border: 2rpx solid;
				box-sizing: border-box;
				padding-bottom: 36rpx;
				padding-top: 45rpx;
				margin: 0 20rpx 20rpx 0;
				flex-direction: column;
				text{
					margin-bottom: 10rpx;
				}
				.lefttop{
					position: absolute;
					left: 0;
					top: 0;
					width: 43rpx;
					height: 43rpx;
				}
			}
		}
		.moneytext{
			display: flex;
			align-items: center;
			width: 100%;
			justify-content: space-between;
			margin-bottom: 42rpx;
			box-sizing: border-box;
			padding-right: 30rpx;
		}
	}
	.listindex{
		width: 690rpx;
		box-sizing: border-box;
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		border-radius: 20rpx;
		margin-bottom: 30rpx;
		.widthdrawalmethodindex{
			display: flex;
			align-items: center;
			width: 100%;
			justify-content: space-between;
			.nextindex{
				display: flex;
				align-items: center;
				.next{
					width: 13rpx;
					height: 23rpx;
					margin-left: 19rpx;
				}
			}
			.itm1{
				position: relative;
				display: flex;
				align-items: center;
				justify-content: center;
				width: 332rpx;
				height: 92rpx;
				border-radius: 10rpx;
				border: 2rpx solid;
				.lefttop{
					position: absolute;
					left: 0;
					top: 0;
					width: 43rpx;
					height: 43rpx;
				}
				.wxicon{
					width: 53rpx;
					height: 53rpx;
					margin-right: 17rpx;
					border-radius: 50%;
				}
			}
		}
		.moneytext{
			display: flex;
			align-items: center;
			width: 100%;
			justify-content: space-between;
			margin-bottom: 42rpx;
		}
		.moneynumber{
			box-sizing: border-box;
			padding-bottom: 40rpx;
			width: 100%;
		}
		.withdrawalfunction{
			margin-top: 30rpx;
			margin-bottom: 30rpx;
		}
	}
		
	.content{
		min-height: 100vh;
		width: 750rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		box-sizing: border-box;
	}
	.topTitle{
		color: #FFFFFF;
		display: flex;
		align-items: center;
		height: 67rpx;
		justify-content: center;
		position: absolute;
		z-index: 10;
		width: 100%;
		.back{
			width: 20rpx;
			height: 31rpx;
			position: absolute;
			left: 31rpx;
		}
	}
</style>
